<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div>
    <div>message: <input class="message-input"/></div>
    <div><button class="sending">发送</button></div>
  </div>
</body>
<script>
  const elmInput = document.querySelector('.message-input');
  const elmSend = document.querySelector('.sending');
  elmSend.addEventListener('click', function () {
    let message = elmInput.value;
    let targetWindow = window.open('./b.html', '__blank')
    setTimeout(function (){
      if ('postMessage' in targetWindow) {
        debugger;
      }
      targetWindow.postMessage(message, '*', null);
    }, 0)
  })
</script>
</html>